<template>
  <div class="view-control">
    <div class="view-control-item" v-for="(item, index) in titles" :class="{ active: currentIndex === index }"
      @click="itemClick(index)" >
      <span>{{ item }}</span>
    </div>
  </div>
</template>
<script>
export default {
  name: "ViewControl",
  props: {
    titles: {
      type: Array,
      default() {
        return []
      }
    }
  },
  methods: {
    itemClick(index) {
      this.currentIndex = index
      this.$emit("tabClick", index)
    }
  },
  data() {
    return {
      currentIndex: 0
    }
  },
}
</script>
<style scoped>
.view-control {
  display: flex;
  /* width: 100%; */
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 14px;
  background-color: #fff;
}

.view-control-item {
  flex: 1;
}

.view-control-item span {
  padding: 2px;
}

.active span {
  border-bottom: 3px solid var(--color-tint);
  color: var(--color-tint);
}
</style>